﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using CheckLift.Common.Intf;
using System.Data.Linq;

namespace CheckLift.Linq
{
    public class LiftData : BaseData
    {
        public LiftData()
        {
            DataLoadOptions options = new DataLoadOptions();

            options.LoadWith<Lift>(c => c.Customer);
            options.LoadWith<Customer>(c => c.Address);
            dc.LoadOptions = options;
        }

        public Lift GetLift(Guid liftId)
        {
            return (from lift in dc.Lifts
                    where lift.Id == liftId
                    select lift).FirstOrDefault<Lift>();
        }

        public ObservableCollection<ILift> GetAllLiftsByUserId(Guid userId)
        {
            return Convert<ILift>(from lift in dc.Lifts
                                  join user_company_link in dc.User_Company_Links on lift.Customer.CompanyId equals user_company_link.CompanyId
                                  where dc.User_Company_Links.Any(p => p.UserId == userId)
                                  select lift);
        }
    }
}
